package com.cn.cs;

import java.sql.*;

import static java.lang.Class.forName;
//插入
public class dome1 {
        public static void main(String[] args)  {
            try {
                forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql1","root","root");
                //获取操作数据库的对象
                PreparedStatement pst =con.prepareStatement("insert into bbb(name,sex,age) values(?,?,?)");
                //解析占位符
                pst.setString(1,"kiname");
                pst.setString(2,"男");
                pst.setInt(3,27);
                pst.setString(1,"k230");
                pst.setString(2,"男");
                pst.setInt(3,27);
                //执行sql语句
                int count=pst.executeUpdate();
                System.out.println(count>0?"操作成功":"操作失败");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }catch (SQLException e1){
                e1.printStackTrace();
            }
        }
}
